<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset=utf8>
</head>
<body>
   <form name="addform" action="1.php" method="post" onsubmit="return checkForm()">
        <table>
            <tr>
                <td>邮箱: </td>
                <td><input type="text" name="email"><span id="emailMsg"></span></td>
            </tr>
            <tr>
                <td>用户名: </td>
                <td><input type="text" name="user"><span id="userMsg"></span></td>
            </tr>
            <tr>
                <td>密码: </td>
                <td><input type="password" name="pass"><span id="passMsg"></span></td>
            </tr>
            <tr>
                <td>确认密码: </td>
                <td><input type="password" name="repass"><span id="repassMsg"></span></td>
            </tr>
            <tr>
                <td></td>
                <td><button type="submit">注册</button></td>
            </tr>
        </table>
    </form>
    <script>
     function checkForm(){
      //获取邮箱
     
     var emailMsg = document.getElementById("emailMsg");
      var userMsg = document.getElementById("userMsg");
      var passMsg = document.getElementById("passMsg");
      var repassMsg = document.getElementById("repassMsg");

      var email = document.addform.email.value;
      //console.log(email);
      if(email.match(/^[\w\.-]+@\w+(\.\w+){1,3}$/)===null)
      {
        emailMsg.innerHTML = "邮箱格式错误";
        userMsg.innerHTML = "";
        passMsg.innerHTML ="";
        repassMsg.innerHTML = "";
        return false;
      }



      var user = document.addform.user.value;
      if(! /\w{6,18}/.test(user))
      {
        userMsg.innerHTML = "用户名格式不对";
        emailMsg.innerHTML = "";
        
        passMsg.innerHTML ="";
        repassMsg.innerHTML = "";
        return false;
      }

      var pass = document.addform.pass.value;
      if(pass.length<6||pass.length>18)
      {
        passMsg.innerHTML = '密码长度不合法';
        emailMsg.innerHTML = "";
        userMsg.innerHTML = "";
       
        repassMsg.innerHTML = "";
        return false;
      }

      var repass = document.addform.repass.value;
      if(pass!==repass)
      {
        repassMsg.innerHTML = '密码不一样';
        emailMsg.innerHTML = "";
        userMsg.innerHTML = "";
        passMsg.innerHTML ="";
       
        return false;
      }



      return true;
    }
    </script>
    
</body>
</html>